from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, confusion_matrix

# 加载鸢尾花数据集并划分数据集 (代码省略，与模型训练示例相同)
iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)

# 使用测试集进行预测
y_pred = model.predict(X_test)

# 打印分类报告，包含精确率、召回率、F1 值、支持度等指标
print("分类报告:\n", classification_report(y_test, y_pred))

# 打印混淆矩阵，展示模型在每个类别上的预测情况
print("\n混淆矩阵:\n", confusion_matrix(y_test, y_pred))